import { viteMockServe } from 'vite-plugin-mock';

const createHomeList = () => {
   return [
      {
         severname: 'home-list',
         'list|15': [
            {
               id: '@increment',
               name: '@cname',
               todayBuy: '@integer(1, 100)',
               monthBuy: '@integer(1, 100)',
               totalBuy: '@integer(1, 100)',
               date: '@date',
               img: '@image',
            },
         ],
      },
      {
         severname: 'home-order',
         'list|6': [
            {
               id: '@increment',
               boolean: '@boolean',
               number: '@integer(1, 100)',
               img: '@image(2*10)',
               date: '@date',
            },
         ],
      },
      {
         severname: 'home-detail',
         id: '@increment',
         boolean: '@boolean',
         number: '@integer(1, 100)',
         date: '@date',
         array: '@range(1, 10)',
      },
      {
         severname: 'home-dictionaries',
         dictionaries: {
            1: '启用',
            2: '禁用',
            3: '待审核',
            A: '电子产品',
            B: '家居用品',
            C: '服装',
         },
      },
   ];
};

export default [
   {
      url: '/mock/dev/tablelist',
      method: 'post',
      response: ({ body }) => {
         const { severname, page, pageSize } = body;
         const checkData = createHomeList().find((item) => item.severname === severname);
         if (!checkData) {
            return {
               code: 201,
               msg: '获取列表信息失败',
               data: null,
            };
         }
         return {
            code: 200,
            msg: 'success',
            data: checkData,
         };
      },
   },
   {
      url: '/mock/dev/orderlist',
      method: 'post',
      response: ({ body }) => {
         const { severname } = body;
         const checkData = createHomeList().find((item) => item.severname === severname);
         if (!checkData) {
            return {
               code: 201,
               msg: '获取订单信息失败',
               data: null,
            };
         }
         return {
            code: 200,
            msg: 'success',
            data: checkData,
         };
      },
   },
   {
      url: '/mock/dev/detail',
      method: 'post',
      response: ({ body }) => {
         const { severname } = body;
         const checkData = createHomeList().find((item) => item.severname === severname);
         if (!checkData) {
            return {
               code: 201,
               msg: '获取详情信息失败',
               data: null,
            };
         }
         return {
            code: 200,
            msg: 'success',
            data: checkData,
         };
      },
   },
   {
      url: '/mock/dev/dictionaries',
      method: 'post',
      response: ({ body }) => {
         const { severname } = body;
         const checkData = createHomeList().find((item) => item.severname === severname);
         if (!checkData) {
            return {
               code: 201,
               msg: '获取字典信息失败',
               data: null,
            };
         }
         return {
            code: 200,
            msg: 'success',
            data: checkData,
         };
      },
   },
];
